package cn.com.cifi.mars.bean.bo.returnPlan;

import cn.com.cifi.mars.bean.dto.returnPlan.CombinationProductDataDto;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 组合业态数据
 * @author: JingYuanXiang
 * @date: 2020/11/16 19:26
 */
@Data
public class CombinationProductDataBO {

    //组合业态数据列表
    private List<CombinationProductDataDto> combinationProductDataList;

    //结转日期Map(key:组团id,(key:组合业态编码,value:结转日期))
    private Map<String, Map<String, Object>> carryOverTimeMap = new HashMap<>();
    //总货值Map(key:组团id,(key:组合业态编码,value:总货值))
    private Map<String, Map<String, BigDecimal>> totalValueMap = new HashMap<>();



    public void initializeMap() {
        //结转日期Map(因Collectors.toMap不支持value为null,将null值转为"")
        this.carryOverTimeMap = combinationProductDataList.stream().collect(Collectors.groupingBy(CombinationProductDataDto::getGroupId,
                Collectors.toMap(CombinationProductDataDto::getCombinationProductCode, s->s.getCarryOverTime() == null ? "" : s.getCarryOverTime())));
        //总货值Map
        this.totalValueMap = combinationProductDataList.stream().collect(Collectors.groupingBy(CombinationProductDataDto::getGroupId,
                Collectors.toMap(CombinationProductDataDto::getCombinationProductCode, CombinationProductDataDto::getTotalValue)));
    }

    /**
     * 获取结转日期
     * @param groupId 组团id
     * @param combinationProductCode 组合业态编码
     * @return
     */
    public LocalDateTime getCarryOverTime(String groupId, String combinationProductCode) {
        Object carryOverTime = carryOverTimeMap.get(groupId).get(combinationProductCode);
        if("".equals(carryOverTime)){
            return null;
        }else {
            return (LocalDateTime)carryOverTime;
        }
    }

    /**
     * 获取结转日期
     * @param groupId 组团id
     * @param combinationProductCode 组合业态编码
     * @return
     */
    public BigDecimal getTotalValue(String groupId, String combinationProductCode) {
        return totalValueMap.get(groupId).get(combinationProductCode);
    }
}
